import { baseURL, } from '!/app.json'

// 上传图片(单个/多个)
export const useUploadImage = async (media: any) => {
    return new Promise<void>((resolve, reject) => {
        const pickedItems = Array.isArray(media) ? media : [media];
        let formData = new FormData();
        for (var i = 0; i < pickedItems.length; i++) {
            let file: any = {
                uri: pickedItems[i].path,
                type: 'multipart/form-data',
                name: 'image/png',
            };
            formData.append('file', file);
            fetch(baseURL + 'Weixin/questionsInfo/questionImg', {
                method: 'POST',
                headers: {
                    Accept: 'application/json',
                    'Content-Type': 'multipart/form-data',
                },
                body: formData,
            })
                .then((response) => response.text())
                .then((res: any) => {
                    const result = eval('(' + res + ')');
                    resolve(result.data);
                    console.log('resultresultresult', result);
                })
                .catch((error) => {
                    reject(error);
                });
        }
    });
};
